package org.example.fileswalk;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.FileTime;
import java.time.Instant;
import java.util.stream.Stream;

public class FilesWalkExample3 {
    public static void main(String[] args) {
        Path path = Paths.get("F:\\迅雷下载\\JetBrainsMono-2.225\\fonts\\ttf");
        setAllFileModifiedDate(path,Instant.now());
    }

    static void setAllFileModifiedDate(Path path, Instant instant){
        try (Stream<Path> pathStream = Files.walk(path)) {
            pathStream.filter(Files::isReadable)
                    .filter(Files::isRegularFile)
                    .forEach(p ->{
                        try {
                            Files.setLastModifiedTime(p, FileTime.from(instant));
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    });
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
